<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/base/taglibs.jsp"%>

<%
	String name = "";
	String pass = "";
	Cookie[] cookies = request.getCookies();
	if (cookies != null) {
		for (int i = 0; i < cookies.length; i++) {
			if (cookies[i].getName().equals("userName")) {
				name = cookies[i].getValue();
			}
			if (cookies[i].getName().equals("password")) {
				pass = cookies[i].getValue(); 
			}
		}
	}
%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/base/loginhead.jsp"%>
<title>登录</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="${ctx}/images/tax2.ico" rel="shortcut icon" />
<link rel="stylesheet" href="static/login/bootstrap.min.css" />
<link rel="stylesheet" href="static/login/css/camera.css" />
<link rel="stylesheet" href="static/login/bootstrap-responsive.min.css" />
<link rel="stylesheet" href="static/login/matrix-login.css" />
<link href="static/login/font-awesome.css" rel="stylesheet" />

</head>

<body>

	<div
		style="width:100%;text-align: center;margin: 0 auto;position: absolute;">
		<div id="loginbox">
			<form action="" method="post" name="loginForm" id="loginForm">
				<div class="control-group normal_text">
					<h3>
						<img src="static/login/logo.png" alt="Logo" />
					</h3>
				</div>
				<div class="control-group">
					<div class="controls">
						<div class="main_input_box">
							<span class="add-on bg_lg"> <i><img height="37"
									src="static/login/user.png" />
							</i> </span><input type="text" name="loginname" id="loginname" value="<%=name %>"
								placeholder="请输入用户名" />
						</div>
					</div>
				</div>
				<div class="control-group">
					<div class="controls">
						<div class="main_input_box">
							<span class="add-on bg_ly"> <i><img height="37"
									src="static/login/suo.png" />
							</i> </span><input type="password" name="password" id="password"
								placeholder="请输入密码" value="<%=pass %>" />
						</div>
					</div>
				</div>
				<div style="float:right;padding-right:10%;">
					<div style="float: left;margin-top:3px;margin-right:2px;">
						<font color="white">记住密码</font>
					</div>
					<div style="float: left;">
						<input name="form-field-checkbox" id="saveid" type="checkbox"
							onclick="savePaw();" style="padding-top:0px;" />
					</div>
				</div>
				<br />
				<div class="form-actions">
					<div style="width:86%;padding-left:8%;">



						<span class="pull-right" style="padding-right:3%;"><a
							href="javascript:quxiao();" class="btn btn-success">取消</a>
						</span> <span class="pull-right"><a onclick="severCheck();"
							class="flip-link btn btn-info" id="to-recover">登录</a>
						</span>

					</div>
				</div>

			</form>


			<div class="controls">
				<div class="main_input_box">
					<font color="white"><span id="nameerr">Copyright © FH
							2100</span>
					</font>
				</div>
			</div>
		</div>
	</div>
	<div id="templatemo_banner_slide" class="container_wapper">
		<div class="camera_wrap camera_emboss" id="camera_slide">
			<div data-src="static/login/images/banner_slide_01.jpg"></div>
			<div data-src="static/login/images/banner_slide_02.jpg"></div>
			<div data-src="static/login/images/banner_slide_03.jpg"></div>
		</div>
		<!-- #camera_wrap_3 -->
	</div>

	<script type="text/javascript">
		window.document.onkeydown = function() {
			var event = window.event || arguments.callee.caller.arguments[0];
			if (event.keyCode == 13) {
				severCheck();
			}
		}
		var loading;
		//服务器校验
		function severCheck() {
			if (check()) {

				var loginname = $("#loginname").val();
				var password = $("#password").val();
				$.ajax({
					type : "POST",
					url : '${ctx}/user/login.action',
					data : {
						username : loginname,
						password : password,
						method : 1
					},
					dataType : 'json',
					cache : false,
					success : function(data) {
						layer.close(loading);
						if (data.loginResult == 1) {
							saveCookie();
							window.location.href = "${ctx}/main.jsp";
						} else if (data.loginResult == 2) {
							$("#loginname").tips({
								side : 1,
								msg : "账号被锁定，请联系管理员",
								bg : '#FF5080',
								time : 3
							});
							$("#loginname").focus();
						} else if (data.loginResult == 3) {
							$("#loginname").tips({
								side : 1,
								msg : "密码错误，请重试",
								bg : '#FF5080',
								time : 3
							});
							$("#loginname").focus();
						} else {
							$("#loginname").tips({
								side : 1,
								msg : "登录失败，请联系管理员",
								bg : '#FF5080',
								time : 3
							});
							$("#loginname").focus();
						}
					}
				});
			}
		}

		$(document).keyup(function(event) {
			if (event.keyCode == 13) {
				$("#to-recover").trigger("click");
			}
		});

		function genTimestamp() {
			var time = new Date();
			return time.getTime();
		}

		//客户端校验
		function check() {
			if ($("#loginname").val() == "") {

				$("#loginname").tips({
					side : 2,
					msg : '用户名不得为空',
					bg : '#AE81FF',
					time : 3
				});

				$("#loginname").focus();
				return false;
			} else {
				$("#loginname").val(jQuery.trim($('#loginname').val()));
			}

			if ($("#password").val() == "") {

				$("#password").tips({
					side : 2,
					msg : '密码不得为空',
					bg : '#AE81FF',
					time : 3
				});

				$("#password").focus();
				return false;
			}
			loading = layer.load();

			return true;
		}

		function savePaw() {
			if (!$("#saveid").attr("checked")) {
				$.cookie('userName', '', {
					expires : -1
				});
				$.cookie('password', '', {
					expires : -1
				});
				$("#loginname").val('');
				$("#password").val('');
			}
		}

		function saveCookie() {
			if ($("#saveid").attr("checked")) {
				$.cookie('userName', $("#loginname").val(), {
					expires : 7
				});
				$.cookie('password', $("#password").val(), {
					expires : 7
				});
			}
		}
		function quxiao() {
			$("#loginname").val('');
			$("#password").val('');
		}
	</script>
	<script>
		//TOCMAT重启之后 点击左侧列表跳转登录首页 
		if (window != top) {
			top.location.href = location.href;
		}
	</script>


	<script src="static/login/js/jquery.easing.1.3.js"></script>
	<script src="static/login/js/jquery.mobile.customized.min.js"></script>
	<script src="static/login/js/camera.min.js"></script>
	<script src="static/login/js/templatemo_script.js"></script>
	<script type="text/javascript" src="js/jquery.tips.js"></script>
</body>
</html>
